WIPx3!
This commit is contained in:
parent
82bc73dd9b
commit
cf6cbd2925
27 changed files with 213 additions and 277 deletions
|
@ -28,9 +28,18 @@ DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent, Connection
|
||||||
, mDeviceId(deviceId)
|
, mDeviceId(deviceId)
|
||||||
, mConnectionSource(connectionSource)
|
, mConnectionSource(connectionSource)
|
||||||
, mLinkProvider(parent)
|
, mLinkProvider(parent)
|
||||||
|
, mPairStatus(NotPaired)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!deviceId.isEmpty());
|
Q_ASSERT(!deviceId.isEmpty());
|
||||||
|
|
||||||
setProperty("deviceId", deviceId);
|
setProperty("deviceId", deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceLink::setPairStatus(DeviceLink::PairStatus status)
|
||||||
|
{
|
||||||
|
if (mPairStatus != status) {
|
||||||
|
mPairStatus = status;
|
||||||
|
Q_EMIT pairStatusChanged(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ class DeviceLink
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum PairStatus : bool { NotPaired, Paired };
|
||||||
enum ConnectionStarted : bool { Locally, Remotely };
|
enum ConnectionStarted : bool { Locally, Remotely };
|
||||||
|
|
||||||
DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource);
|
DeviceLink(const QString& deviceId, LinkProvider* parent, ConnectionStarted connectionSource);
|
||||||
|
@ -47,16 +48,21 @@ public:
|
||||||
const QString& deviceId() { return mDeviceId; }
|
const QString& deviceId() { return mDeviceId; }
|
||||||
LinkProvider* provider() { return mLinkProvider; }
|
LinkProvider* provider() { return mLinkProvider; }
|
||||||
|
|
||||||
virtual PairingHandler* createPairingHandler(Device* device) = 0;
|
|
||||||
virtual bool sendPackage(NetworkPackage& np) = 0;
|
virtual bool sendPackage(NetworkPackage& np) = 0;
|
||||||
virtual bool sendPackageEncrypted(NetworkPackage& np) = 0;
|
virtual bool sendPackageEncrypted(NetworkPackage& np) = 0;
|
||||||
|
|
||||||
ConnectionStarted connectionSource() const {
|
//user actions
|
||||||
return mConnectionSource;
|
virtual void requestPairing() = 0;
|
||||||
}
|
virtual void unpair() = 0;
|
||||||
|
|
||||||
|
ConnectionStarted connectionSource() const { return mConnectionSource; }
|
||||||
|
|
||||||
|
PairStatus pairStatus() const { return mPairStatus; }
|
||||||
|
void setPairStatus(PairStatus status);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void receivedPackage(const NetworkPackage& np);
|
void receivedPackage(const NetworkPackage& np);
|
||||||
|
void pairStatusChanged(DeviceLink::PairStatus status);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QCA::PrivateKey mPrivateKey;
|
QCA::PrivateKey mPrivateKey;
|
||||||
|
@ -65,6 +71,7 @@ private:
|
||||||
const QString mDeviceId;
|
const QString mDeviceId;
|
||||||
const ConnectionStarted mConnectionSource;
|
const ConnectionStarted mConnectionSource;
|
||||||
LinkProvider* mLinkProvider;
|
LinkProvider* mLinkProvider;
|
||||||
|
PairStatus mPairStatus;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "uploadjob.h"
|
#include "uploadjob.h"
|
||||||
#include "downloadjob.h"
|
#include "downloadjob.h"
|
||||||
#include "socketlinereader.h"
|
#include "socketlinereader.h"
|
||||||
#include "lanpairinghandler.h"
|
#include "lanlinkprovider.h"
|
||||||
|
|
||||||
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource)
|
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource)
|
||||||
: DeviceLink(deviceId, parent, connectionSource)
|
: DeviceLink(deviceId, parent, connectionSource)
|
||||||
|
@ -49,11 +49,6 @@ QString LanDeviceLink::name()
|
||||||
return "LanLink"; // Should be same in both android and kde version
|
return "LanLink"; // Should be same in both android and kde version
|
||||||
}
|
}
|
||||||
|
|
||||||
PairingHandler* LanDeviceLink::createPairingHandler(Device* device)
|
|
||||||
{
|
|
||||||
return new LanPairingHandler(device->id());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LanDeviceLink::sendPackageEncrypted(NetworkPackage& np)
|
bool LanDeviceLink::sendPackageEncrypted(NetworkPackage& np)
|
||||||
{
|
{
|
||||||
if (np.hasPayload()) {
|
if (np.hasPayload()) {
|
||||||
|
@ -124,3 +119,13 @@ void LanDeviceLink::dataReceived()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LanDeviceLink::requestPairing()
|
||||||
|
{
|
||||||
|
qobject_cast<LanLinkProvider*>(provider())->requestPairing(deviceId());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LanDeviceLink::unpair()
|
||||||
|
{
|
||||||
|
setPairStatus(NotPaired);
|
||||||
|
}
|
||||||
|
|
|
@ -39,18 +39,22 @@ public:
|
||||||
LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource);
|
LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource);
|
||||||
|
|
||||||
virtual QString name() Q_DECL_OVERRIDE;
|
virtual QString name() Q_DECL_OVERRIDE;
|
||||||
virtual PairingHandler* createPairingHandler(Device* device) Q_DECL_OVERRIDE;
|
|
||||||
bool sendPackage(NetworkPackage& np) override;
|
bool sendPackage(NetworkPackage& np) override;
|
||||||
bool sendPackageEncrypted(NetworkPackage& np) override;
|
bool sendPackageEncrypted(NetworkPackage& np) override;
|
||||||
UploadJob* sendPayload(NetworkPackage& np);
|
UploadJob* sendPayload(NetworkPackage& np);
|
||||||
|
|
||||||
|
virtual void unpair() override;
|
||||||
|
|
||||||
|
void requestPairing();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void dataReceived();
|
void dataReceived();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SocketLineReader* mSocketLineReader;
|
SocketLineReader* mSocketLineReader;
|
||||||
bool onSsl;
|
|
||||||
|
|
||||||
|
QCA::PublicKey m_publicKey;
|
||||||
|
QSslCertificate m_certificate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "../../daemon.h"
|
#include "../../daemon.h"
|
||||||
#include "landevicelink.h"
|
#include "landevicelink.h"
|
||||||
|
#include "lanpairinghandler.h"
|
||||||
#include <kdeconnectconfig.h>
|
#include <kdeconnectconfig.h>
|
||||||
#include <QDBusPendingReply>
|
#include <QDBusPendingReply>
|
||||||
#include <QtNetwork/qsslcipher.h>
|
#include <QtNetwork/qsslcipher.h>
|
||||||
|
@ -269,7 +270,7 @@ void LanLinkProvider::sslErrors(const QList<QSslError>& errors)
|
||||||
disconnect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
|
disconnect(socket, SIGNAL(encrypted()), this, SLOT(encrypted()));
|
||||||
disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
|
disconnect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
|
||||||
|
|
||||||
foreach(QSslError error, errors) {
|
foreach(const QSslError &error, errors) {
|
||||||
qCDebug(KDECONNECT_CORE) << "SSL Error :" << error.errorString();
|
qCDebug(KDECONNECT_CORE) << "SSL Error :" << error.errorString();
|
||||||
switch (error.error()) {
|
switch (error.error()) {
|
||||||
case QSslError::CertificateSignatureFailed:
|
case QSslError::CertificateSignatureFailed:
|
||||||
|
@ -438,7 +439,23 @@ void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, Netwo
|
||||||
}
|
}
|
||||||
|
|
||||||
mLinks[deviceLink->deviceId()] = deviceLink;
|
mLinks[deviceLink->deviceId()] = deviceLink;
|
||||||
|
LanPairingHandler* ph = mPairingHandlers.value(deviceLink->deviceId());
|
||||||
|
if (ph) {
|
||||||
|
ph->setDeviceLink(deviceLink);
|
||||||
|
}
|
||||||
|
|
||||||
Q_EMIT onConnectionReceived(*receivedPackage, deviceLink);
|
Q_EMIT onConnectionReceived(*receivedPackage, deviceLink);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LanLinkProvider::requestPairing(const QString& deviceId)
|
||||||
|
{
|
||||||
|
LanPairingHandler* ph = mPairingHandlers.value(deviceId);
|
||||||
|
if (!ph) {
|
||||||
|
new LanPairingHandler(deviceId);
|
||||||
|
ph->setDeviceLink(mLinks[deviceId]);
|
||||||
|
mPairingHandlers[deviceId] = ph;
|
||||||
|
}
|
||||||
|
|
||||||
|
ph->requestPairing();
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "landevicelink.h"
|
#include "landevicelink.h"
|
||||||
|
|
||||||
|
class LanPairingHandler;
|
||||||
class LanLinkProvider
|
class LanLinkProvider
|
||||||
: public LinkProvider
|
: public LinkProvider
|
||||||
{
|
{
|
||||||
|
@ -43,6 +44,8 @@ public:
|
||||||
QString name() override { return "LanLinkProvider"; }
|
QString name() override { return "LanLinkProvider"; }
|
||||||
int priority() override { return PRIORITY_HIGH; }
|
int priority() override { return PRIORITY_HIGH; }
|
||||||
|
|
||||||
|
void requestPairing(const QString &deviceId);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual void onNetworkChange() override;
|
virtual void onNetworkChange() override;
|
||||||
virtual void onStart() override;
|
virtual void onStart() override;
|
||||||
|
@ -70,6 +73,7 @@ private:
|
||||||
quint16 mTcpPort;
|
quint16 mTcpPort;
|
||||||
|
|
||||||
QMap<QString, DeviceLink*> mLinks;
|
QMap<QString, DeviceLink*> mLinks;
|
||||||
|
QMap<QString, LanPairingHandler*> mPairingHandlers;
|
||||||
|
|
||||||
struct PendingConnect {
|
struct PendingConnect {
|
||||||
NetworkPackage* np;
|
NetworkPackage* np;
|
||||||
|
|
|
@ -30,20 +30,12 @@
|
||||||
LanPairingHandler::LanPairingHandler(const QString& deviceId)
|
LanPairingHandler::LanPairingHandler(const QString& deviceId)
|
||||||
: PairingHandler()
|
: PairingHandler()
|
||||||
, m_deviceId(deviceId)
|
, m_deviceId(deviceId)
|
||||||
|
, m_status(NotPaired)
|
||||||
{
|
{
|
||||||
m_pairingTimeout.setSingleShot(true);
|
m_pairingTimeout.setSingleShot(true);
|
||||||
m_pairingTimeout.setInterval(30 * 1000); //30 seconds of timeout
|
m_pairingTimeout.setInterval(30 * 1000); //30 seconds of timeout
|
||||||
connect(&m_pairingTimeout, SIGNAL(timeout()),
|
connect(&m_pairingTimeout, SIGNAL(timeout()),
|
||||||
this, SLOT(pairingTimeout()));
|
this, SLOT(pairingTimeout()));
|
||||||
/*
|
|
||||||
m_publicKey = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "publicKey", QString());
|
|
||||||
m_certificate = KdeConnectConfig::instance()->getDeviceProperty(deviceId, "certificate", QString());
|
|
||||||
*/
|
|
||||||
if (!m_publicKey.isNull()) {
|
|
||||||
setPairStatus(PairStatus::Paired);
|
|
||||||
} else {
|
|
||||||
setPairStatus(PairStatus::NotPaired);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPairingHandler::createPairPackage(NetworkPackage& np)
|
void LanPairingHandler::createPairPackage(NetworkPackage& np)
|
||||||
|
@ -65,8 +57,8 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
|
||||||
if (wantsPair == isPaired()) {
|
if (wantsPair == isPaired()) {
|
||||||
// qCDebug(KDECONNECT_CORE) << "Already" << (wantsPair? "paired":"unpaired");
|
// qCDebug(KDECONNECT_CORE) << "Already" << (wantsPair? "paired":"unpaired");
|
||||||
if (isPairRequested()) {
|
if (isPairRequested()) {
|
||||||
setPairStatus(PairStatus::NotPaired);
|
setInternalPairStatus(NotPaired);
|
||||||
Q_EMIT pairingFailed(i18n("Canceled by other peer"));
|
Q_EMIT pairingError(i18n("Canceled by other peer"));
|
||||||
return;
|
return;
|
||||||
} else if (isPaired()) {
|
} else if (isPaired()) {
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +66,7 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
|
||||||
* and we don't know it, unpair it internally
|
* and we don't know it, unpair it internally
|
||||||
*/
|
*/
|
||||||
KdeConnectConfig::instance()->removeTrustedDevice(m_deviceId);
|
KdeConnectConfig::instance()->removeTrustedDevice(m_deviceId);
|
||||||
setPairStatus(PairingHandler::NotPaired);
|
setInternalPairStatus(NotPaired);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +77,9 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
|
||||||
|
|
||||||
if (QCA::RSAPublicKey::fromPEM(keyString).isNull()) {
|
if (QCA::RSAPublicKey::fromPEM(keyString).isNull()) {
|
||||||
if (isPairRequested()) {
|
if (isPairRequested()) {
|
||||||
setPairStatus(PairStatus::NotPaired);
|
setInternalPairStatus(NotPaired);
|
||||||
}
|
}
|
||||||
Q_EMIT pairingFailed(i18n("Received incorrect key"));
|
Q_EMIT pairingError(i18n("Received incorrect key"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,9 +97,8 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Daemon::instance()->requestPairing(m_device);
|
Daemon::instance()->requestPairing(this);
|
||||||
//m_pairStatus = PairStatus::RequestedByPeer;
|
setInternalPairStatus(RequestedByPeer);
|
||||||
setPairStatus(PairStatus::RequestedByPeer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { //wantsPair == false
|
} else { //wantsPair == false
|
||||||
|
@ -115,27 +106,27 @@ void LanPairingHandler::packageReceived(const NetworkPackage& np)
|
||||||
qCDebug(KDECONNECT_CORE) << "Unpair request";
|
qCDebug(KDECONNECT_CORE) << "Unpair request";
|
||||||
|
|
||||||
if (isPairRequested()) {
|
if (isPairRequested()) {
|
||||||
Q_EMIT pairingFailed(i18n("Canceled by other peer"));
|
Q_EMIT pairingError(i18n("Canceled by other peer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
setPairStatus(PairStatus::NotPaired);
|
setInternalPairStatus(NotPaired);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanPairingHandler::requestPairing()
|
bool LanPairingHandler::requestPairing()
|
||||||
{
|
{
|
||||||
switch (pairStatus()) {
|
switch (m_status) {
|
||||||
case PairStatus::Paired:
|
case Paired:
|
||||||
Q_EMIT pairingFailed(i18n(deviceLink()->name().append(" : Already paired").toLatin1().data()));
|
Q_EMIT pairingError(i18n(deviceLink()->name().append(" : Already paired").toLatin1().data()));
|
||||||
return false;
|
return false;
|
||||||
case PairStatus::Requested:
|
case Requested:
|
||||||
Q_EMIT pairingFailed(i18n(deviceLink()->name().append(" : Pairing already requested for this device").toLatin1().data()));
|
Q_EMIT pairingError(i18n(deviceLink()->name().append(" : Pairing already requested for this device").toLatin1().data()));
|
||||||
return false;
|
return false;
|
||||||
case PairStatus::RequestedByPeer:
|
case RequestedByPeer:
|
||||||
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
|
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
|
||||||
acceptPairing();
|
acceptPairing();
|
||||||
return false;
|
return false;
|
||||||
case PairStatus::NotPaired:
|
case NotPaired:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +135,7 @@ bool LanPairingHandler::requestPairing()
|
||||||
bool success;
|
bool success;
|
||||||
success = deviceLink()->sendPackage(np);
|
success = deviceLink()->sendPackage(np);
|
||||||
if (success) {
|
if (success) {
|
||||||
setPairStatus(PairStatus::Requested);
|
setInternalPairStatus(Requested);
|
||||||
m_pairingTimeout.start();
|
m_pairingTimeout.start();
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
|
@ -158,7 +149,7 @@ bool LanPairingHandler::acceptPairing()
|
||||||
bool success;
|
bool success;
|
||||||
success = deviceLink()->sendPackage(np);
|
success = deviceLink()->sendPackage(np);
|
||||||
if (success) {
|
if (success) {
|
||||||
setPairStatus(PairStatus::Paired);
|
setInternalPairStatus(Paired);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +160,7 @@ void LanPairingHandler::rejectPairing()
|
||||||
np.set("pair", false);
|
np.set("pair", false);
|
||||||
np.set("link", deviceLink()->name());
|
np.set("link", deviceLink()->name());
|
||||||
deviceLink()->sendPackage(np);
|
deviceLink()->sendPackage(np);
|
||||||
setPairStatus(PairStatus::NotPaired);
|
setInternalPairStatus(NotPaired);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPairingHandler::unpair() {
|
void LanPairingHandler::unpair() {
|
||||||
|
@ -177,7 +168,7 @@ void LanPairingHandler::unpair() {
|
||||||
np.set("pair", false);
|
np.set("pair", false);
|
||||||
np.set("link", deviceLink()->name());
|
np.set("link", deviceLink()->name());
|
||||||
deviceLink()->sendPackage(np);
|
deviceLink()->sendPackage(np);
|
||||||
setPairStatus(PairStatus::NotPaired);
|
setInternalPairStatus(NotPaired);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanPairingHandler::pairingTimeout()
|
void LanPairingHandler::pairingTimeout()
|
||||||
|
@ -186,6 +177,16 @@ void LanPairingHandler::pairingTimeout()
|
||||||
np.set("pair", false);
|
np.set("pair", false);
|
||||||
np.set("name", deviceLink()->name());
|
np.set("name", deviceLink()->name());
|
||||||
deviceLink()->sendPackage(np);
|
deviceLink()->sendPackage(np);
|
||||||
setPairStatus(PairStatus::NotPaired); //Will emit the change as well
|
setInternalPairStatus(NotPaired); //Will emit the change as well
|
||||||
Q_EMIT pairingFailed(i18n("Timed out"));
|
Q_EMIT pairingError(i18n("Timed out"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LanPairingHandler::setInternalPairStatus(LanPairingHandler::InternalPairStatus status)
|
||||||
|
{
|
||||||
|
m_status = status;
|
||||||
|
if (status == Paired) {
|
||||||
|
deviceLink()->setPairStatus(DeviceLink::Paired);
|
||||||
|
} else {
|
||||||
|
deviceLink()->setPairStatus(DeviceLink::NotPaired);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,14 @@ class LanPairingHandler
|
||||||
: public PairingHandler
|
: public PairingHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum InternalPairStatus {
|
||||||
|
NotPaired,
|
||||||
|
Requested,
|
||||||
|
RequestedByPeer,
|
||||||
|
Paired,
|
||||||
|
};
|
||||||
|
|
||||||
LanPairingHandler(const QString& deviceId);
|
LanPairingHandler(const QString& deviceId);
|
||||||
virtual ~LanPairingHandler() { }
|
virtual ~LanPairingHandler() { }
|
||||||
|
|
||||||
|
@ -40,15 +48,19 @@ public:
|
||||||
virtual void rejectPairing() Q_DECL_OVERRIDE;
|
virtual void rejectPairing() Q_DECL_OVERRIDE;
|
||||||
virtual void unpair() Q_DECL_OVERRIDE;
|
virtual void unpair() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
bool isPairRequested() const { return m_status == Requested; }
|
||||||
|
bool isPaired() const { return m_status == Paired; }
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
virtual void pairingTimeout();
|
void pairingTimeout();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void setInternalPairStatus(InternalPairStatus status);
|
||||||
|
|
||||||
QTimer m_pairingTimeout;
|
QTimer m_pairingTimeout;
|
||||||
QString m_deviceId;
|
QString m_deviceId;
|
||||||
QCA::PublicKey m_publicKey;
|
|
||||||
QSslCertificate m_certificate;
|
|
||||||
|
|
||||||
|
InternalPairStatus m_status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
class DeviceLink;
|
class DeviceLink;
|
||||||
|
|
||||||
class LinkProvider
|
class KDECONNECTCORE_EXPORT LinkProvider
|
||||||
: public QObject
|
: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -4,7 +4,7 @@ set(backends_kdeconnect_SRCS
|
||||||
|
|
||||||
backends/loopback/loopbacklinkprovider.cpp
|
backends/loopback/loopbacklinkprovider.cpp
|
||||||
backends/loopback/loopbackdevicelink.cpp
|
backends/loopback/loopbackdevicelink.cpp
|
||||||
backends/loopback/loopbackpairinghandler.cpp
|
# backends/loopback/loopbackpairinghandler.cpp
|
||||||
|
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,10 +34,6 @@ QString LoopbackDeviceLink::name()
|
||||||
return "LoopbackLink"; // Should be similar to android
|
return "LoopbackLink"; // Should be similar to android
|
||||||
}
|
}
|
||||||
|
|
||||||
PairingHandler* LoopbackDeviceLink::createPairingHandler(Device *device)
|
|
||||||
{
|
|
||||||
return new LoopbackPairingHandler(device->id());
|
|
||||||
}
|
|
||||||
bool LoopbackDeviceLink::sendPackageEncrypted(NetworkPackage& input)
|
bool LoopbackDeviceLink::sendPackageEncrypted(NetworkPackage& input)
|
||||||
{
|
{
|
||||||
return sendPackage(input);
|
return sendPackage(input);
|
||||||
|
|
|
@ -33,10 +33,11 @@ public:
|
||||||
LoopbackDeviceLink(const QString& d, LoopbackLinkProvider* a);
|
LoopbackDeviceLink(const QString& d, LoopbackLinkProvider* a);
|
||||||
|
|
||||||
virtual QString name() override;
|
virtual QString name() override;
|
||||||
virtual PairingHandler* createPairingHandler(Device* device) override;
|
|
||||||
virtual bool sendPackage(NetworkPackage& np) override;
|
virtual bool sendPackage(NetworkPackage& np) override;
|
||||||
virtual bool sendPackageEncrypted(NetworkPackage& np) override;
|
virtual bool sendPackageEncrypted(NetworkPackage& np) override;
|
||||||
|
|
||||||
|
virtual void requestPairing() override {}
|
||||||
|
virtual void unpair() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -39,10 +39,10 @@ bool LoopbackPairingHandler::requestPairing()
|
||||||
case PairStatus::Paired:
|
case PairStatus::Paired:
|
||||||
Q_EMIT pairingFailed(deviceLink()->name().append(" : Already paired").toLatin1().data());
|
Q_EMIT pairingFailed(deviceLink()->name().append(" : Already paired").toLatin1().data());
|
||||||
return false;
|
return false;
|
||||||
case PairStatus ::Requested:
|
case PairStatus::Requested:
|
||||||
Q_EMIT pairingFailed(deviceLink()->name().append(" : Pairing already requested for this device").toLatin1().data());
|
Q_EMIT pairingFailed(deviceLink()->name().append(" : Pairing already requested for this device").toLatin1().data());
|
||||||
return false;
|
return false;
|
||||||
case PairStatus ::RequestedByPeer:
|
case PairStatus::RequestedByPeer:
|
||||||
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
|
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
|
||||||
acceptPairing();
|
acceptPairing();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2015 Vineet Garg <grg.vineet@gmail.com>
|
* Copyright 2015 Albert Vaca Cintora <albertvaka@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
@ -20,15 +20,16 @@
|
||||||
|
|
||||||
#include "pairinghandler.h"
|
#include "pairinghandler.h"
|
||||||
|
|
||||||
PairingHandler::PairingHandler()
|
PairingHandler::PairingHandler(DeviceLink* parent)
|
||||||
: m_deviceLink(nullptr)
|
: QObject(parent)
|
||||||
, m_pairStatus(NotPaired)
|
, m_deviceLink(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PairingHandler::setDeviceLink(DeviceLink *dl)
|
void PairingHandler::setDeviceLink(DeviceLink *dl)
|
||||||
{
|
{
|
||||||
|
setParent(dl);
|
||||||
m_deviceLink = dl;
|
m_deviceLink = dl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,26 +38,3 @@ DeviceLink* PairingHandler::deviceLink() const
|
||||||
return m_deviceLink;
|
return m_deviceLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PairingHandler::linkDestroyed(QObject* o)
|
|
||||||
{
|
|
||||||
DeviceLink* dl = static_cast<DeviceLink*>(o);
|
|
||||||
if (dl == m_deviceLink) { // Check if same link is destroyed
|
|
||||||
m_deviceLink = Q_NULLPTR;
|
|
||||||
Q_EMIT linkNull();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PairingHandler::setPairStatus(PairingHandler::PairStatus status)
|
|
||||||
{
|
|
||||||
if (m_pairStatus != status) {
|
|
||||||
PairStatus oldStatus = m_pairStatus;
|
|
||||||
m_pairStatus = status;
|
|
||||||
Q_EMIT pairStatusChanged(status, oldStatus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PairingHandler::PairStatus PairingHandler::pairStatus() const
|
|
||||||
{
|
|
||||||
return m_pairStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -37,56 +37,31 @@
|
||||||
* After that if any one of the link is paired, then we can say that device is paired, so new link will pair automatically
|
* After that if any one of the link is paired, then we can say that device is paired, so new link will pair automatically
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class PairingHandler : public QObject
|
class KDECONNECTCORE_EXPORT PairingHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
PairingHandler(DeviceLink* parent = 0);
|
||||||
//TODO: Can we simplify this to just Paired/NotPaired, and leave the detailed status as an backend-specific thing?
|
|
||||||
enum PairStatus {
|
|
||||||
NotPaired,
|
|
||||||
Requested,
|
|
||||||
RequestedByPeer,
|
|
||||||
Paired,
|
|
||||||
};
|
|
||||||
|
|
||||||
PairingHandler();
|
|
||||||
virtual ~PairingHandler() { }
|
virtual ~PairingHandler() { }
|
||||||
|
|
||||||
|
DeviceLink* deviceLink() const;
|
||||||
void setDeviceLink(DeviceLink* dl);
|
void setDeviceLink(DeviceLink* dl);
|
||||||
bool isPaired() const { return m_pairStatus == PairStatus::Paired; }
|
|
||||||
bool isPairRequested() const { return m_pairStatus == PairStatus::Requested; }
|
|
||||||
|
|
||||||
|
|
||||||
virtual void createPairPackage(NetworkPackage& np) = 0;
|
virtual void createPairPackage(NetworkPackage& np) = 0;
|
||||||
virtual void packageReceived(const NetworkPackage& np) = 0;
|
virtual void packageReceived(const NetworkPackage& np) = 0;
|
||||||
|
virtual void unpair() = 0;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
virtual bool requestPairing() = 0;
|
virtual bool requestPairing() = 0;
|
||||||
virtual bool acceptPairing() = 0;
|
virtual bool acceptPairing() = 0;
|
||||||
virtual void rejectPairing() = 0;
|
virtual void rejectPairing() = 0;
|
||||||
virtual void unpair() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
DeviceLink* deviceLink() const;
|
|
||||||
void setPairStatus(PairStatus status);
|
|
||||||
PairStatus pairStatus() const;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void linkDestroyed(QObject*);
|
|
||||||
virtual void pairingTimeout() = 0;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void pairStatusChanged(PairStatus status, PairStatus previousStatus);
|
void pairingError(const QString& errorMessage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceLink* m_deviceLink; // We keep the latest link here, if this is destroyed without new link, linkDestroyed is emitted and device will destroy pairing handler
|
DeviceLink* m_deviceLink; // We keep the latest link here, if this is destroyed without new link, linkDestroyed is emitted and device will destroy pairing handler
|
||||||
PairStatus m_pairStatus;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void pairingDone();
|
|
||||||
void unpairingDone();
|
|
||||||
void pairingFailed(const QString& error);
|
|
||||||
void linkNull();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ void Daemon::removeDevice(Device* device)
|
||||||
void Daemon::cleanDevices()
|
void Daemon::cleanDevices()
|
||||||
{
|
{
|
||||||
Q_FOREACH(Device* device, d->mDevices) {
|
Q_FOREACH(Device* device, d->mDevices) {
|
||||||
if (device->pairStatus() == PairingHandler::NotPaired && device->connectionSource() == DeviceLink::ConnectionStarted::Remotely) {
|
if (!device->isTrusted() && device->connectionSource() == DeviceLink::ConnectionStarted::Remotely) {
|
||||||
removeDevice(device);
|
removeDevice(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,12 +148,12 @@ Device *Daemon::getDevice(QString deviceId) {
|
||||||
return Q_NULLPTR;
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Daemon::devices(bool onlyReachable, bool onlyPaired) const
|
QStringList Daemon::devices(bool onlyReachable, bool onlyTrusted) const
|
||||||
{
|
{
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
Q_FOREACH(Device* device, d->mDevices) {
|
Q_FOREACH(Device* device, d->mDevices) {
|
||||||
if (onlyReachable && !device->isReachable()) continue;
|
if (onlyReachable && !device->isReachable()) continue;
|
||||||
if (onlyPaired && !device->isPaired()) continue;
|
if (onlyTrusted && !device->isTrusted()) continue;
|
||||||
ret.append(device->id());
|
ret.append(device->id());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -179,7 +179,7 @@ void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink*
|
||||||
|
|
||||||
//we discard the connections that we created but it's not paired.
|
//we discard the connections that we created but it's not paired.
|
||||||
//we keep the remotely initiated ones, since the remotes require them
|
//we keep the remotely initiated ones, since the remotes require them
|
||||||
if (!isDiscoveringDevices() && !device->isPaired() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
|
if (!isDiscoveringDevices() && !device->isTrusted() && dl->connectionSource() == DeviceLink::ConnectionStarted::Locally) {
|
||||||
device->deleteLater();
|
device->deleteLater();
|
||||||
} else {
|
} else {
|
||||||
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
|
connect(device, SIGNAL(reachableStatusChanged()), this, SLOT(onDeviceStatusChanged()));
|
||||||
|
@ -197,7 +197,7 @@ void Daemon::onDeviceStatusChanged()
|
||||||
|
|
||||||
//qCDebug(KDECONNECT_CORE) << "Device" << device->name() << "status changed. Reachable:" << device->isReachable() << ". Paired: " << device->isPaired();
|
//qCDebug(KDECONNECT_CORE) << "Device" << device->name() << "status changed. Reachable:" << device->isReachable() << ". Paired: " << device->isPaired();
|
||||||
|
|
||||||
if (!device->isReachable() && !device->isPaired()) {
|
if (!device->isReachable() && !device->isTrusted()) {
|
||||||
//qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name();
|
//qCDebug(KDECONNECT_CORE) << "Destroying device" << device->name();
|
||||||
removeDevice(device);
|
removeDevice(device);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
QList<Device*> devicesList() const;
|
QList<Device*> devicesList() const;
|
||||||
|
|
||||||
virtual void requestPairing(Device *d) = 0;
|
virtual void requestPairing(PairingHandler *d) = 0;
|
||||||
virtual void reportError(const QString &title, const QString &description) = 0;
|
virtual void reportError(const QString &title, const QString &description) = 0;
|
||||||
virtual QNetworkAccessManager* networkAccessManager();
|
virtual QNetworkAccessManager* networkAccessManager();
|
||||||
|
|
||||||
|
|
135
core/device.cpp
135
core/device.cpp
|
@ -76,7 +76,6 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin
|
||||||
|
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_pairingHandlers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::hasPlugin(const QString& name) const
|
bool Device::hasPlugin(const QString& name) const
|
||||||
|
@ -98,7 +97,7 @@ void Device::reloadPlugins()
|
||||||
QSet<QString> supportedOutgoingInterfaces;
|
QSet<QString> supportedOutgoingInterfaces;
|
||||||
QStringList unsupportedPlugins;
|
QStringList unsupportedPlugins;
|
||||||
|
|
||||||
if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices
|
if (isTrusted() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices
|
||||||
|
|
||||||
KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins");
|
KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins");
|
||||||
|
|
||||||
|
@ -169,7 +168,7 @@ void Device::reloadPlugins()
|
||||||
}
|
}
|
||||||
Q_EMIT pluginsChanged();
|
Q_EMIT pluginsChanged();
|
||||||
|
|
||||||
if (capabilitiesChanged && isReachable() && isPaired())
|
if (capabilitiesChanged && isReachable() && isTrusted())
|
||||||
{
|
{
|
||||||
NetworkPackage np(PACKAGE_TYPE_CAPABILITIES);
|
NetworkPackage np(PACKAGE_TYPE_CAPABILITIES);
|
||||||
np.set<QStringList>("IncomingCapabilities", newSupportedIncomingInterfaces);
|
np.set<QStringList>("IncomingCapabilities", newSupportedIncomingInterfaces);
|
||||||
|
@ -183,59 +182,50 @@ QString Device::pluginsConfigFile() const
|
||||||
return KdeConnectConfig::instance()->deviceConfigDir(id()).absoluteFilePath("config");
|
return KdeConnectConfig::instance()->deviceConfigDir(id()).absoluteFilePath("config");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isPairRequested() const
|
|
||||||
{
|
|
||||||
bool isPairRequested = false;
|
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers) {
|
|
||||||
isPairRequested = isPairRequested || ph->isPairRequested();
|
|
||||||
}
|
|
||||||
return isPairRequested;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::requestPair()
|
void Device::requestPair()
|
||||||
{
|
{
|
||||||
if (isPaired()) {
|
if (isTrusted()) {
|
||||||
Q_EMIT pairingFailed(i18n("Already paired"));
|
Q_EMIT pairingError(i18n("Already paired"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isReachable()) {
|
if (!isReachable()) {
|
||||||
Q_EMIT pairingFailed(i18n("Device not reachable"));
|
Q_EMIT pairingError(i18n("Device not reachable"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = false;
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers.values()) {
|
dl->requestPairing();
|
||||||
success = success || ph->requestPairing(); // If one of many pairing handlers can successfully request pairing, consider it success
|
|
||||||
}
|
|
||||||
if (!success) {
|
|
||||||
Q_EMIT pairingFailed(i18n("Error contacting device"));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::unpair()
|
void Device::unpair()
|
||||||
{
|
{
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers.values()) {
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
ph->unpair();
|
dl->unpair();
|
||||||
}
|
}
|
||||||
|
KdeConnectConfig::instance()->removeTrustedDevice(id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::pairStatusChanged(PairingHandler::PairStatus status, PairingHandler::PairStatus oldStatus)
|
void Device::pairStatusChanged(DeviceLink::PairStatus status)
|
||||||
{
|
{
|
||||||
if (oldStatus == PairingHandler::Paired && status == PairingHandler::NotPaired) {
|
if (status == DeviceLink::NotPaired) {
|
||||||
KdeConnectConfig::instance()->removeTrustedDevice(m_deviceId);
|
KdeConnectConfig::instance()->removeTrustedDevice(id());
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers.values()) {
|
|
||||||
ph->unpair();
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
|
if (dl != sender()) {
|
||||||
|
dl->unpair();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
KdeConnectConfig::instance()->addTrustedDevice(id(), name(), type());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldStatus == PairingHandler::NotPaired && status == PairingHandler::Paired) {
|
reloadPlugins(); //Will load/unload plugins
|
||||||
reloadPlugins(); //Will unload the plugins
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT pairingChanged(status == PairingHandler::Paired);
|
|
||||||
|
|
||||||
|
bool isTrusted = (status == DeviceLink::Paired);
|
||||||
|
Q_EMIT trustedChanged(isTrusted? Trusted : NotTrusted);
|
||||||
|
Q_ASSERT(isTrusted == this->isTrusted());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool lessThan(DeviceLink* p1, DeviceLink* p2)
|
static bool lessThan(DeviceLink* p1, DeviceLink* p2)
|
||||||
|
@ -281,16 +271,8 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// One pairing handler per type of device link, so check if there is already a pairing handler of same type, if not add it to the list
|
connect(link, SIGNAL(pairStatusChanged(PairStatus)), this, SLOT(pairStatusChanged(PairStatus, PairStatus)));
|
||||||
if (!m_pairingHandlers.contains(link->name())) {
|
connect(link, SIGNAL(pairingFailed(const QString&)), this, SIGNAL(pairingFailed(const QString&)));
|
||||||
PairingHandler* pairingHandler = link->createPairingHandler(this);
|
|
||||||
m_pairingHandlers.insert(link->name(), pairingHandler);
|
|
||||||
connect(m_pairingHandlers[link->name()], SIGNAL(linkNull()), this, SLOT(destroyPairingHandler()));
|
|
||||||
connect(m_pairingHandlers[link->name()], SIGNAL(pairStatusChanged(PairStatus, PairStatus)), this, SLOT(pairStatusChanged(PairStatus, PairStatus)));
|
|
||||||
connect(m_pairingHandlers[link->name()], SIGNAL(pairingFailed(const QString&)), this, SIGNAL(pairingFailed(const QString&)));
|
|
||||||
}
|
|
||||||
m_pairingHandlers[link->name()]->setDeviceLink(link);
|
|
||||||
connect(link, SIGNAL(destroyed(QObject*)), m_pairingHandlers[link->name()], SLOT(linkDestroyed(QObject*)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::linkDestroyed(QObject* o)
|
void Device::linkDestroyed(QObject* o)
|
||||||
|
@ -300,7 +282,7 @@ void Device::linkDestroyed(QObject* o)
|
||||||
|
|
||||||
void Device::removeLink(DeviceLink* link)
|
void Device::removeLink(DeviceLink* link)
|
||||||
{
|
{
|
||||||
m_deviceLinks.removeOne(link);
|
m_deviceLinks.removeAll(link);
|
||||||
|
|
||||||
//qCDebug(KDECONNECT_CORE) << "RemoveLink" << m_deviceLinks.size() << "links remaining";
|
//qCDebug(KDECONNECT_CORE) << "RemoveLink" << m_deviceLinks.size() << "links remaining";
|
||||||
|
|
||||||
|
@ -310,16 +292,9 @@ void Device::removeLink(DeviceLink* link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::destroyPairingHandler()
|
|
||||||
{
|
|
||||||
PairingHandler* ph = qobject_cast<PairingHandler*>(sender());
|
|
||||||
m_pairingHandlers.remove(m_pairingHandlers.key(ph));
|
|
||||||
delete ph;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Device::sendPackage(NetworkPackage& np)
|
bool Device::sendPackage(NetworkPackage& np)
|
||||||
{
|
{
|
||||||
if (np.type() != PACKAGE_TYPE_PAIR && isPaired()) {
|
if (np.type() != PACKAGE_TYPE_PAIR && isTrusted()) {
|
||||||
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
Q_FOREACH(DeviceLink* dl, m_deviceLinks) {
|
||||||
if (dl->sendPackageEncrypted(np)) return true;
|
if (dl->sendPackageEncrypted(np)) return true;
|
||||||
}
|
}
|
||||||
|
@ -335,14 +310,8 @@ bool Device::sendPackage(NetworkPackage& np)
|
||||||
|
|
||||||
void Device::privateReceivedPackage(const NetworkPackage& np)
|
void Device::privateReceivedPackage(const NetworkPackage& np)
|
||||||
{
|
{
|
||||||
if (np.type() == PACKAGE_TYPE_PAIR) {
|
Q_ASSERT(np.type() != PACKAGE_TYPE_PAIR);
|
||||||
|
if (np.type() == PACKAGE_TYPE_CAPABILITIES) {
|
||||||
// If PACKAGE_TYPE_PAIR, send it to pairing handlers without thinking
|
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers) {
|
|
||||||
ph->packageReceived(np);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (np.type() == PACKAGE_TYPE_CAPABILITIES) {
|
|
||||||
QSet<QString> newIncomingCapabilities = np.get<QStringList>("IncomingCapabilities", QStringList()).toSet();
|
QSet<QString> newIncomingCapabilities = np.get<QStringList>("IncomingCapabilities", QStringList()).toSet();
|
||||||
QSet<QString> newOutgoingCapabilities = np.get<QStringList>("OutgoingCapabilities", QStringList()).toSet();
|
QSet<QString> newOutgoingCapabilities = np.get<QStringList>("OutgoingCapabilities", QStringList()).toSet();
|
||||||
|
|
||||||
|
@ -351,7 +320,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
|
||||||
m_outgoingCapabilities = newOutgoingCapabilities;
|
m_outgoingCapabilities = newOutgoingCapabilities;
|
||||||
reloadPlugins();
|
reloadPlugins();
|
||||||
}
|
}
|
||||||
} else if (isPaired()) {
|
} else if (isTrusted()) {
|
||||||
QList<KdeConnectPlugin*> plugins = m_pluginsByIncomingInterface.values(np.type());
|
QList<KdeConnectPlugin*> plugins = m_pluginsByIncomingInterface.values(np.type());
|
||||||
foreach(KdeConnectPlugin* plugin, plugins) {
|
foreach(KdeConnectPlugin* plugin, plugins) {
|
||||||
plugin->receivePackage(np);
|
plugin->receivePackage(np);
|
||||||
|
@ -363,38 +332,11 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::rejectPairing()
|
bool Device::isTrusted() const
|
||||||
{
|
{
|
||||||
qCDebug(KDECONNECT_CORE) << "Rejected pairing";
|
return KdeConnectConfig::instance()->trustedDevices().contains(id());
|
||||||
|
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers.values()) {
|
|
||||||
ph->rejectPairing();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT pairingFailed(i18n("Canceled by the user"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::acceptPairing()
|
|
||||||
{
|
|
||||||
qCDebug(KDECONNECT_CORE) << "Accepted pairing";
|
|
||||||
|
|
||||||
bool success = false;
|
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers) {
|
|
||||||
success = success || ph->acceptPairing();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Device::isPaired() const
|
|
||||||
{
|
|
||||||
Q_FOREACH(PairingHandler* ph, m_pairingHandlers) {
|
|
||||||
if (ph->isPaired()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DeviceLink::ConnectionStarted Device::connectionSource() const
|
DeviceLink::ConnectionStarted Device::connectionSource() const
|
||||||
{
|
{
|
||||||
DeviceLink::ConnectionStarted ret = DeviceLink::Remotely;
|
DeviceLink::ConnectionStarted ret = DeviceLink::Remotely;
|
||||||
|
@ -434,7 +376,7 @@ QString Device::type2str(Device::DeviceType deviceType) {
|
||||||
|
|
||||||
QString Device::statusIconName() const
|
QString Device::statusIconName() const
|
||||||
{
|
{
|
||||||
return iconForStatus(isReachable(), isPaired());
|
return iconForStatus(isReachable(), isTrusted());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Device::iconName() const
|
QString Device::iconName() const
|
||||||
|
@ -443,7 +385,7 @@ QString Device::iconName() const
|
||||||
return iconForStatus(true, false);
|
return iconForStatus(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Device::iconForStatus(bool reachable, bool paired) const
|
QString Device::iconForStatus(bool reachable, bool trusted) const
|
||||||
{
|
{
|
||||||
Device::DeviceType deviceType = m_deviceType;
|
Device::DeviceType deviceType = m_deviceType;
|
||||||
if (deviceType == Device::Unknown) {
|
if (deviceType == Device::Unknown) {
|
||||||
|
@ -452,7 +394,7 @@ QString Device::iconForStatus(bool reachable, bool paired) const
|
||||||
deviceType = Device::Device::Laptop; // We don't have desktop icon yet
|
deviceType = Device::Device::Laptop; // We don't have desktop icon yet
|
||||||
}
|
}
|
||||||
|
|
||||||
QString status = (reachable? (paired? QStringLiteral("connected") : QStringLiteral("disconnected")) : QStringLiteral("trusted"));
|
QString status = (reachable? (trusted? QStringLiteral("connected") : QStringLiteral("disconnected")) : QStringLiteral("trusted"));
|
||||||
QString type = type2str(deviceType);
|
QString type = type2str(deviceType);
|
||||||
|
|
||||||
return type+'-'+status;
|
return type+'-'+status;
|
||||||
|
@ -466,11 +408,6 @@ void Device::setName(const QString &name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PairingHandler::PairStatus Device::pairStatus() const
|
|
||||||
{
|
|
||||||
return isPaired()? PairingHandler::Paired : PairingHandler::NotPaired;
|
|
||||||
}
|
|
||||||
|
|
||||||
KdeConnectPlugin* Device::plugin(const QString& pluginName) const
|
KdeConnectPlugin* Device::plugin(const QString& pluginName) const
|
||||||
{
|
{
|
||||||
return m_plugins[pluginName];
|
return m_plugins[pluginName];
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <QSslCertificate>
|
#include <QSslCertificate>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "backends/pairinghandler.h"
|
|
||||||
#include "networkpackage.h"
|
#include "networkpackage.h"
|
||||||
#include "backends/devicelink.h"
|
#include "backends/devicelink.h"
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ class KDECONNECTCORE_EXPORT Device
|
||||||
Q_PROPERTY(QString iconName READ iconName CONSTANT)
|
Q_PROPERTY(QString iconName READ iconName CONSTANT)
|
||||||
Q_PROPERTY(QString statusIconName READ statusIconName)
|
Q_PROPERTY(QString statusIconName READ statusIconName)
|
||||||
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged)
|
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged)
|
||||||
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairingChanged)
|
Q_PROPERTY(bool isTrusted READ isTrusted NOTIFY trustedChanged)
|
||||||
Q_PROPERTY(QStringList unsupportedPlugins READ unsupportedPlugins NOTIFY pluginsChanged)
|
Q_PROPERTY(QStringList unsupportedPlugins READ unsupportedPlugins NOTIFY pluginsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -60,6 +59,11 @@ public:
|
||||||
Tablet,
|
Tablet,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TrustStatus {
|
||||||
|
NotTrusted,
|
||||||
|
Trusted
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores the @p device from the saved configuration
|
* Restores the @p device from the saved configuration
|
||||||
*
|
*
|
||||||
|
@ -89,8 +93,7 @@ public:
|
||||||
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
|
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
|
||||||
void removeLink(DeviceLink*);
|
void removeLink(DeviceLink*);
|
||||||
|
|
||||||
Q_SCRIPTABLE bool isPaired() const;
|
Q_SCRIPTABLE bool isTrusted() const;
|
||||||
Q_SCRIPTABLE bool isPairRequested() const;
|
|
||||||
|
|
||||||
Q_SCRIPTABLE QStringList availableLinks() const;
|
Q_SCRIPTABLE QStringList availableLinks() const;
|
||||||
bool isReachable() const { return !m_deviceLinks.isEmpty(); }
|
bool isReachable() const { return !m_deviceLinks.isEmpty(); }
|
||||||
|
@ -104,8 +107,6 @@ public:
|
||||||
void setPluginEnabled(const QString& pluginName, bool enabled);
|
void setPluginEnabled(const QString& pluginName, bool enabled);
|
||||||
bool isPluginEnabled(const QString& pluginName) const;
|
bool isPluginEnabled(const QString& pluginName) const;
|
||||||
|
|
||||||
PairingHandler::PairStatus pairStatus() const;
|
|
||||||
|
|
||||||
DeviceLink::ConnectionStarted connectionSource() const;
|
DeviceLink::ConnectionStarted connectionSource() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
@ -114,25 +115,20 @@ public Q_SLOTS:
|
||||||
|
|
||||||
//Dbus operations
|
//Dbus operations
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
Q_SCRIPTABLE void requestPair();
|
Q_SCRIPTABLE void requestPair(); //to all links
|
||||||
Q_SCRIPTABLE void unpair();
|
Q_SCRIPTABLE void unpair(); //from all links
|
||||||
Q_SCRIPTABLE void reloadPlugins(); //From kconf
|
Q_SCRIPTABLE void reloadPlugins(); //from kconf
|
||||||
void acceptPairing();
|
|
||||||
void rejectPairing();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void privateReceivedPackage(const NetworkPackage& np);
|
void privateReceivedPackage(const NetworkPackage& np);
|
||||||
void linkDestroyed(QObject* o);
|
void linkDestroyed(QObject* o);
|
||||||
void destroyPairingHandler();
|
void pairStatusChanged(DeviceLink::PairStatus current);
|
||||||
|
|
||||||
void pairStatusChanged(PairingHandler::PairStatus current, PairingHandler::PairStatus old);
|
|
||||||
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
Q_SCRIPTABLE void pluginsChanged();
|
Q_SCRIPTABLE void pluginsChanged();
|
||||||
Q_SCRIPTABLE void reachableStatusChanged();
|
Q_SCRIPTABLE void reachableStatusChanged();
|
||||||
Q_SCRIPTABLE void pairingChanged(bool paired);
|
Q_SCRIPTABLE void trustedChanged(bool trusted);
|
||||||
Q_SCRIPTABLE void pairingFailed(const QString& error);
|
Q_SCRIPTABLE void pairingError(const QString& error);
|
||||||
Q_SCRIPTABLE void nameChanged(const QString& name);
|
Q_SCRIPTABLE void nameChanged(const QString& name);
|
||||||
|
|
||||||
private: //Methods
|
private: //Methods
|
||||||
|
@ -150,10 +146,10 @@ private: //Fields (TODO: dPointer!)
|
||||||
|
|
||||||
QVector<DeviceLink*> m_deviceLinks;
|
QVector<DeviceLink*> m_deviceLinks;
|
||||||
QHash<QString, KdeConnectPlugin*> m_plugins;
|
QHash<QString, KdeConnectPlugin*> m_plugins;
|
||||||
QMap<QString, PairingHandler*> m_pairingHandlers;
|
|
||||||
|
//Capabilities stuff
|
||||||
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingInterface;
|
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingInterface;
|
||||||
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByOutgoingInterface;
|
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByOutgoingInterface;
|
||||||
|
|
||||||
QSet<QString> m_incomingCapabilities;
|
QSet<QString> m_incomingCapabilities;
|
||||||
QSet<QString> m_outgoingCapabilities;
|
QSet<QString> m_outgoingCapabilities;
|
||||||
QStringList m_supportedIncomingInterfaces;
|
QStringList m_supportedIncomingInterfaces;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "core/daemon.h"
|
#include "core/daemon.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
|
#include "core/backends/pairinghandler.h"
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
|
||||||
#ifdef HAVE_TELEPATHY
|
#ifdef HAVE_TELEPATHY
|
||||||
|
@ -88,16 +89,16 @@ public:
|
||||||
, m_nam(Q_NULLPTR)
|
, m_nam(Q_NULLPTR)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void requestPairing(Device* d) Q_DECL_OVERRIDE
|
void requestPairing(PairingHandler* d) Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
KNotification* notification = new KNotification("pairingRequest");
|
KNotification* notification = new KNotification("pairingRequest");
|
||||||
notification->setIconName(QStringLiteral("dialog-information"));
|
notification->setIconName(QStringLiteral("dialog-information"));
|
||||||
notification->setComponentName("kdeconnect");
|
notification->setComponentName("kdeconnect");
|
||||||
notification->setText(i18n("Pairing request from %1", d->name()));
|
notification->setText(i18n("Pairing request from %1", d->deviceLink()->name()));
|
||||||
notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
|
notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
|
||||||
connect(notification, &KNotification::ignored, d, &Device::rejectPairing);
|
connect(notification, &KNotification::ignored, d, &PairingHandler::rejectPairing);
|
||||||
connect(notification, &KNotification::action1Activated, d, &Device::acceptPairing);
|
connect(notification, &KNotification::action1Activated, d, &PairingHandler::acceptPairing);
|
||||||
connect(notification, &KNotification::action2Activated, d, &Device::rejectPairing);
|
connect(notification, &KNotification::action2Activated, d, &PairingHandler::rejectPairing);
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent)
|
||||||
: OrgKdeKdeconnectDeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
: OrgKdeKdeconnectDeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent)
|
||||||
, m_id(id)
|
, m_id(id)
|
||||||
{
|
{
|
||||||
connect(this, &OrgKdeKdeconnectDeviceInterface::pairingChanged, this, &DeviceDbusInterface::pairingChangedProxy);
|
connect(this, &OrgKdeKdeconnectDeviceInterface::trustedChanged, this, &DeviceDbusInterface::trustedChangedProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceDbusInterface::~DeviceDbusInterface()
|
DeviceDbusInterface::~DeviceDbusInterface()
|
||||||
|
|
|
@ -58,7 +58,7 @@ class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// TODO: Workaround because OrgKdeKdeconnectDeviceInterface is not generating
|
// TODO: Workaround because OrgKdeKdeconnectDeviceInterface is not generating
|
||||||
// the signals for the properties
|
// the signals for the properties
|
||||||
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairingChangedProxy)
|
Q_PROPERTY(bool isTrusted READ isTrusted NOTIFY trustedChangedProxy)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeviceDbusInterface(const QString& deviceId, QObject* parent = nullptr);
|
explicit DeviceDbusInterface(const QString& deviceId, QObject* parent = nullptr);
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
Q_SCRIPTABLE void pluginCall(const QString &plugin, const QString &method);
|
Q_SCRIPTABLE void pluginCall(const QString &plugin, const QString &method);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void pairingChangedProxy(bool paired);
|
void trustedChangedProxy(bool paired);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_id;
|
const QString m_id;
|
||||||
|
|
|
@ -105,7 +105,7 @@ void DevicesModel::deviceAdded(const QString& id)
|
||||||
bool onlyPaired = (m_displayFilter & StatusFilterFlag::Paired);
|
bool onlyPaired = (m_displayFilter & StatusFilterFlag::Paired);
|
||||||
bool onlyReachable = (m_displayFilter & StatusFilterFlag::Reachable);
|
bool onlyReachable = (m_displayFilter & StatusFilterFlag::Reachable);
|
||||||
|
|
||||||
if ((onlyReachable && !dev->isReachable()) || (onlyPaired && !dev->isPaired())) {
|
if ((onlyReachable && !dev->isReachable()) || (onlyPaired && !dev->isTrusted())) {
|
||||||
delete dev;
|
delete dev;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -255,16 +255,16 @@ QVariant DevicesModel::data(const QModelIndex& index, int role) const
|
||||||
case NameModelRole:
|
case NameModelRole:
|
||||||
return device->name();
|
return device->name();
|
||||||
case Qt::ToolTipRole: {
|
case Qt::ToolTipRole: {
|
||||||
bool paired = device->isPaired();
|
bool trusted = device->isTrusted();
|
||||||
bool reachable = device->isReachable();
|
bool reachable = device->isReachable();
|
||||||
QString status = reachable? (paired? i18n("Device trusted and connected") : i18n("Device not trusted")) : i18n("Device disconnected");
|
QString status = reachable? (trusted? i18n("Device trusted and connected") : i18n("Device not trusted")) : i18n("Device disconnected");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
case StatusModelRole: {
|
case StatusModelRole: {
|
||||||
int status = StatusFilterFlag::NoFilter;
|
int status = StatusFilterFlag::NoFilter;
|
||||||
if (device->isReachable()) {
|
if (device->isReachable()) {
|
||||||
status |= StatusFilterFlag::Reachable;
|
status |= StatusFilterFlag::Reachable;
|
||||||
if (device->isPaired()) status |= StatusFilterFlag::Paired;
|
if (device->isTrusted()) status |= StatusFilterFlag::Paired;
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
25
kcm/kcm.cpp
25
kcm/kcm.cpp
|
@ -180,22 +180,15 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
|
||||||
}
|
}
|
||||||
|
|
||||||
kcmUi->messages->setVisible(false);
|
kcmUi->messages->setVisible(false);
|
||||||
if (currentDevice->isPairRequested()) {
|
kcmUi->progressBar->setVisible(false);
|
||||||
kcmUi->progressBar->setVisible(true);
|
if (currentDevice->isTrusted()) {
|
||||||
kcmUi->unpair_button->setVisible(false);
|
kcmUi->unpair_button->setVisible(true);
|
||||||
kcmUi->pair_button->setVisible(false);
|
kcmUi->pair_button->setVisible(false);
|
||||||
kcmUi->ping_button->setVisible(false);
|
kcmUi->ping_button->setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
kcmUi->progressBar->setVisible(false);
|
kcmUi->unpair_button->setVisible(false);
|
||||||
if (currentDevice->isPaired()) {
|
kcmUi->pair_button->setVisible(true);
|
||||||
kcmUi->unpair_button->setVisible(true);
|
kcmUi->ping_button->setVisible(false);
|
||||||
kcmUi->pair_button->setVisible(false);
|
|
||||||
kcmUi->ping_button->setVisible(true);
|
|
||||||
} else {
|
|
||||||
kcmUi->unpair_button->setVisible(false);
|
|
||||||
kcmUi->pair_button->setVisible(true);
|
|
||||||
kcmUi->ping_button->setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resetDeviceView();
|
resetDeviceView();
|
||||||
|
|
||||||
|
@ -223,7 +216,7 @@ void KdeConnectKcm::resetDeviceView()
|
||||||
kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id()));
|
kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id()));
|
||||||
|
|
||||||
kcmUi->name_label->setText(currentDevice->name());
|
kcmUi->name_label->setText(currentDevice->name());
|
||||||
kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)"));
|
kcmUi->status_label->setText(currentDevice->isTrusted()? i18n("(trusted)") : i18n("(not trusted)"));
|
||||||
|
|
||||||
const QList<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/"));
|
const QList<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/"));
|
||||||
QList<KPluginInfo> availablePluginInfo;
|
QList<KPluginInfo> availablePluginInfo;
|
||||||
|
@ -286,7 +279,7 @@ void KdeConnectKcm::pairingChanged(bool paired)
|
||||||
|
|
||||||
kcmUi->pair_button->setVisible(!paired);
|
kcmUi->pair_button->setVisible(!paired);
|
||||||
kcmUi->unpair_button->setVisible(paired);
|
kcmUi->unpair_button->setVisible(paired);
|
||||||
kcmUi->progressBar->setVisible(senderDevice->isPairRequested());
|
kcmUi->progressBar->setVisible(false);
|
||||||
kcmUi->ping_button->setVisible(paired);
|
kcmUi->ping_button->setVisible(paired);
|
||||||
kcmUi->status_label->setText(paired ? i18n("(paired)") : i18n("(unpaired)"));
|
kcmUi->status_label->setText(paired ? i18n("(paired)") : i18n("(unpaired)"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,7 @@ void DeviceTest::testPairedDevice()
|
||||||
QCOMPARE(device.name(), deviceName);
|
QCOMPARE(device.name(), deviceName);
|
||||||
QCOMPARE(device.type(), deviceType);
|
QCOMPARE(device.type(), deviceType);
|
||||||
|
|
||||||
QCOMPARE(device.isPaired(), true);
|
QCOMPARE(device.isTrusted(), true);
|
||||||
QCOMPARE(device.isPairRequested(), false);
|
|
||||||
|
|
||||||
QCOMPARE(device.isReachable(), false);
|
QCOMPARE(device.isReachable(), false);
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ void DeviceTest::testPairedDevice()
|
||||||
QCOMPARE(device.availableLinks().contains(linkProvider.name()), false);
|
QCOMPARE(device.availableLinks().contains(linkProvider.name()), false);
|
||||||
|
|
||||||
device.unpair();
|
device.unpair();
|
||||||
QCOMPARE(device.isPaired(), false);
|
QCOMPARE(device.isTrusted(), false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +105,7 @@ void DeviceTest::testUnpairedDevice()
|
||||||
QCOMPARE(device.name(), deviceName);
|
QCOMPARE(device.name(), deviceName);
|
||||||
QCOMPARE(device.type(), deviceType);
|
QCOMPARE(device.type(), deviceType);
|
||||||
|
|
||||||
QCOMPARE(device.isPaired(), false);
|
QCOMPARE(device.isTrusted(), false);
|
||||||
QCOMPARE(device.isPairRequested(), false);
|
|
||||||
|
|
||||||
QCOMPARE(device.isReachable(), true);
|
QCOMPARE(device.isReachable(), true);
|
||||||
QCOMPARE(device.availableLinks().contains(linkProvider.name()), true);
|
QCOMPARE(device.availableLinks().contains(linkProvider.name()), true);
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "core/daemon.h"
|
#include "core/daemon.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
#include "core/kdeconnectplugin.h"
|
#include "core/kdeconnectplugin.h"
|
||||||
|
#include <backends/pairinghandler.h>
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
|
||||||
class TestDaemon : public Daemon
|
class TestDaemon : public Daemon
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestPairing(Device* d) Q_DECL_OVERRIDE
|
void requestPairing(PairingHandler* d) Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
d->acceptPairing();
|
d->acceptPairing();
|
||||||
}
|
}
|
||||||
|
@ -88,7 +89,7 @@ class PluginLoadTest : public QObject
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY(d);
|
QVERIFY(d);
|
||||||
QVERIFY(d->isPaired());
|
QVERIFY(d->isTrusted());
|
||||||
QVERIFY(d->isReachable());
|
QVERIFY(d->isReachable());
|
||||||
|
|
||||||
d->setPluginEnabled("kdeconnect_mousepad", false);
|
d->setPluginEnabled("kdeconnect_mousepad", false);
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "core/daemon.h"
|
#include "core/daemon.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
#include "core/kdeconnectplugin.h"
|
#include "core/kdeconnectplugin.h"
|
||||||
|
#include <backends/pairinghandler.h>
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
|
||||||
class TestDaemon : public Daemon
|
class TestDaemon : public Daemon
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestPairing(Device* d) Q_DECL_OVERRIDE
|
void requestPairing(PairingHandler* d) Q_DECL_OVERRIDE
|
||||||
{
|
{
|
||||||
d->acceptPairing();
|
d->acceptPairing();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ class TestSendFile : public QObject
|
||||||
}
|
}
|
||||||
QVERIFY(d);
|
QVERIFY(d);
|
||||||
QCOMPARE(d->isReachable(), true);
|
QCOMPARE(d->isReachable(), true);
|
||||||
QCOMPARE(d->isPaired(), true);
|
QCOMPARE(d->isTrusted(), true);
|
||||||
|
|
||||||
QByteArray content("12312312312313213123213123");
|
QByteArray content("12312312312313213123213123");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue