Unverified Commit 6792b45f authored by Albert Vaca Cintora's avatar Albert Vaca Cintora Committed by Àlex Fiestas

Adapt to new API in master

parent d711547a
......@@ -14,7 +14,6 @@ find_package(Qt5 5.2 REQUIRED COMPONENTS Quick Bluetooth)
find_package(KF5 REQUIRED COMPONENTS I18n ConfigWidgets DBusAddons)
find_package(KF5DocTools)
find_package(Qca-qt5 2.1.0 REQUIRED)
include_directories(${CMAKE_SOURCE_DIR})
......
......@@ -4,6 +4,9 @@ set(backends_kdeconnect_SRCS
backends/bluetooth/bluetoothlinkprovider.cpp
backends/bluetooth/bluetoothdevicelink.cpp
backends/bluetooth/bluetoothpairinghandler.cpp
backends/bluetooth/bluetoothdownloadjob.cpp
backends/bluetooth/bluetoothuploadjob.cpp
PARENT_SCOPE
)
/**
* Copyright 2015 Saikrishna Arcot <saiarcot895@gmail.com>
* Copyright 2016 Saikrishna Arcot <saiarcot895@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -21,90 +21,86 @@
#include "bluetoothdevicelink.h"
#include "../linkprovider.h"
#include "bluetoothlinkprovider.h"
#include "bluetoothuploadjob.h"
#include "bluetoothdownloadjob.h"
#include "core_debug.h"
BluetoothDeviceLink::BluetoothDeviceLink(const QString& deviceId, LinkProvider* parent, QBluetoothSocket* socket)
: DeviceLink(deviceId, parent)
, mBluetoothSocket(new DeviceLineReader(socket))
, mSocketReader(new DeviceLineReader(socket, this))
, mBluetoothSocket(socket)
, mPairingHandler(new BluetoothPairingHandler(this))
{
connect(mBluetoothSocket, SIGNAL(readyRead()),
connect(mSocketReader, SIGNAL(readyRead()),
this, SLOT(dataReceived()));
//We take ownership of the socket.
//When the link provider distroys us,
//When the link provider destroys us,
//the socket (and the reader) will be
//destroyed as well
connect(mBluetoothSocket, SIGNAL(disconnected()),
this, SLOT(deleteLater()));
mBluetoothSocket->setParent(this);
connect(mBluetoothSocket, SIGNAL(disconnected()), this, SLOT(deleteLater()));
}
/*void BluetoothDeviceLink::sendPayload(const QSharedPointer<QIODevice>& mInput)
QString BluetoothDeviceLink::name()
{
while ( mInput->bytesAvailable() > 0 )
{
qint64 bytes = qMin(mInput->bytesAvailable(), (qint64)4096);
int w = mBluetoothSocket->write(mInput->read(bytes));
if (w<0) {
qWarning() << "error when writing data to upload" << bytes << mInput->bytesAvailable();
break;
}
else
{
while ( mBluetoothSocket->flush() );
}
}
mInput->close();
}*/
bool BluetoothDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np)
{
np.encrypt(key);
return sendPackage(np);
return "BluetoothLink"; // Should be same in both android and kde version
}
bool BluetoothDeviceLink::sendPackage(NetworkPackage& np)
{
int written = mBluetoothSocket->write(np.serialize());
if (np.hasPayload()) {
qWarning() << "Bluetooth backend does not support payloads.";
qCWarning(KDECONNECT_CORE) << "Sending packages with payload over bluetooth not yet supported";
/*
BluetoothUploadJob* uploadJob = new BluetoothUploadJob(np.payload(), mBluetoothSocket->peerAddress(), this);
np.setPayloadTransferInfo(uploadJob->transferInfo());
uploadJob->start();
*/
}
int written = mSocketReader->write(np.serialize());
return (written != -1);
}
void BluetoothDeviceLink::dataReceived()
{
if (mBluetoothSocket->bytesAvailable() == 0) return;
void BluetoothDeviceLink::userRequestsPair() {
mPairingHandler->requestPairing();
}
const QByteArray package = mBluetoothSocket->readLine();
void BluetoothDeviceLink::userRequestsUnpair() {
mPairingHandler->unpair();
}
//kDebug(debugArea()) << "BluetoothDeviceLink dataReceived" << package;
bool BluetoothDeviceLink::linkShouldBeKeptAlive() {
return pairStatus() == Paired;
}
NetworkPackage unserialized(QString::null);
NetworkPackage::unserialize(package, &unserialized);
if (unserialized.isEncrypted()) {
//mPrivateKey should always be set when device link is added to device, no null-checking done here
NetworkPackage decrypted(QString::null);
unserialized.decrypt(mPrivateKey, &decrypted);
void BluetoothDeviceLink::dataReceived()
{
if (mSocketReader->bytesAvailable() == 0) return;
if (decrypted.hasPayloadTransferInfo()) {
qWarning() << "Bluetooth backend does not support payloads.";
}
const QByteArray serializedPackage = mSocketReader->readLine();
Q_EMIT receivedPackage(decrypted);
//qCDebug(KDECONNECT_CORE) << "BluetoothDeviceLink dataReceived" << package;
} else {
if (unserialized.hasPayloadTransferInfo()) {
qWarning() << "Ignoring unencrypted payload";
}
NetworkPackage package(QString::null);
NetworkPackage::unserialize(serializedPackage, &package);
Q_EMIT receivedPackage(unserialized);
if (package.type() == PACKAGE_TYPE_PAIR) {
//TODO: Handle pair/unpair requests and forward them (to the pairing handler?)
mPairingHandler->packageReceived(package);
return;
}
if (package.hasPayloadTransferInfo()) {
BluetoothDownloadJob* downloadJob = new BluetoothDownloadJob(mBluetoothSocket->peerAddress(),
package.payloadTransferInfo(), this);
downloadJob->start();
package.setPayload(downloadJob->payload(), package.payloadSize());
}
if (mBluetoothSocket->bytesAvailable() > 0) {
Q_EMIT receivedPackage(package);
if (mSocketReader->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
}
}
/**
* Copyright 2015 Saikrishna Arcot <saiarcot895@gmail.com>
* Copyright 2016 Saikrishna Arcot <saiarcot895@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -27,8 +27,9 @@
#include "../devicelink.h"
#include "../devicelinereader.h"
#include "bluetoothpairinghandler.h"
class BluetoothDeviceLink
class KDECONNECTCORE_EXPORT BluetoothDeviceLink
: public DeviceLink
{
Q_OBJECT
......@@ -36,16 +37,22 @@ class BluetoothDeviceLink
public:
BluetoothDeviceLink(const QString& deviceId, LinkProvider* parent, QBluetoothSocket* socket);
bool sendPackage(NetworkPackage& np);
bool sendPackageEncrypted(QCA::PublicKey& key, NetworkPackage& np);
virtual QString name() override;
bool sendPackage(NetworkPackage& np) override;
virtual void userRequestsPair() override;
virtual void userRequestsUnpair() override;
virtual bool linkShouldBeKeptAlive() override;
private Q_SLOTS:
void dataReceived();
private:
DeviceLineReader* mBluetoothSocket;
DeviceLineReader* mSocketReader;
QBluetoothSocket* mBluetoothSocket;
BluetoothPairingHandler* mPairingHandler;
//void sendPayload(const QSharedPointer<QIODevice>& mInput);
void sendMessage(const QString mMessage);
};
......
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
/*
* Copyright 2016 Saikrishna Arcot <saiarcot895@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -18,32 +18,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "kdeconnectplugin_config.h"
#include <kcm/kcm.h>
#include "bluetoothdownloadjob.h"
KdeConnectPluginConfig::KdeConnectPluginConfig(QObject* parent, const QVariantList& args)
: KCModule(SftpConfigFactory::componentData(), parent)
, mGlobalConfig(KSharedConfig::openConfig("kdeconnect/plugins/pausemusic"))
BluetoothDownloadJob::BluetoothDownloadJob(const QBluetoothAddress &remoteAddress, const QVariantMap &transferInfo, QObject *parent)
: QObject(parent)
, mRemoteAddress(remoteAddress)
, mTransferUuid(QBluetoothUuid(transferInfo.value("uuid").toString()))
, mSocket(new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol))
{
KdeConnectKcm* kcm = 0;
QObject* kcmCandidate = parent->parentWidget();
while (kcmCandidate) {
//qDebug() << kcmCandidate;
if (kcmCandidate->objectName() == "KdeConnectKcm") {
kcm = qobject_cast<KdeConnectKcm*>(kcmCandidate);
break;
}
kcmCandidate = kcmCandidate->parent();
}
if (kcm) {
kcm->selectedDevice()->id();
}
}
KdeConnectPluginConfig::~KdeConnectPluginConfig()
QSharedPointer<QIODevice> BluetoothDownloadJob::payload() const
{
return mSocket.staticCast<QIODevice>();
}
void BluetoothDownloadJob::start()
{
connect(mSocket.data(), SIGNAL(disconnected()), this, SLOT(deleteLater()));
mSocket->connectToService(mRemoteAddress, mTransferUuid, QIODevice::ReadOnly);
}
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
/*
* Copyright 2016 Saikrishna Arcot <saiarcot895@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -18,32 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECTPLUGINCONFIG_H
#define KDECONNECTPLUGINCONFIG_H
#ifndef BLUETOOTHDOWNLOADJOB_H
#define BLUETOOTHDOWNLOADJOB_H
#include "kdeconnectcore_export.h"
#include <kcmodule.h>
#include <QIODevice>
#include <QThread>
#include <QVariantMap>
#include <QSharedPointer>
#include <QBluetoothAddress>
#include <QBluetoothUuid>
#include <QBluetoothSocket>
struct DeviceDbusInterface;
class KDECONNECTCORE_EXPORT KdeConnectPluginConfig
: public KCModule
class BluetoothDownloadJob
: public QObject
{
Q_OBJECT
public:
KdeConnectPluginConfig(QObject* parent, const QVariantList& args);
virtual ~KdeConnectPluginConfig();
QString deviceId() { return mDeviceId; }
//TODO: Add these two to the Plugin as well
KSharedConfigPtr deviceConfig() { return mDeviceConfig; }
KSharedConfigPtr globalConfig() { return mGlobalConfig; }
explicit BluetoothDownloadJob(const QBluetoothAddress &remoteAddress, const QVariantMap &transferInfo, QObject* parent = 0);
QSharedPointer<QIODevice> payload() const;
void start();
private:
QString mDeviceId;
KSharedConfigPtr mGlobalConfig;
KSharedConfigPtr mDeviceConfig;
QBluetoothAddress mRemoteAddress;
QBluetoothUuid mTransferUuid;
QSharedPointer<QBluetoothSocket> mSocket;
};
#endif
#endif // BLUETOOTHDOWNLOADJOB_H
/**
* Copyright 2015 Saikrishna Arcot <saiarcot895@gmail.com>
* Copyright 2016 Saikrishna Arcot <saiarcot895@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -28,22 +28,13 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QBluetoothServiceInfo>
#include "bluetoothdevicelink.h"
BluetoothLinkProvider::BluetoothLinkProvider()
{
if (!mDevice.isValid()) {
qCWarning(KDECONNECT_CORE) << "No local device found";
mBluetoothServer = NULL;
return;
}
mBluetoothServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
mBluetoothServer->setSecurityFlags(QBluetooth::Encryption | QBluetooth::Secure);
connect(mBluetoothServer, SIGNAL(newConnection()), this, SLOT(serverNewConnection()));
mServiceUuid = QBluetoothUuid(QString("576bf9a0-98c9-11e4-bc89-0002a5d5c51b"));
mServiceUuid = QBluetoothUuid(QString("185f3df4-3268-4e3f-9fca-d4d5059915bd"));
connectTimer = new QTimer(this);
connectTimer->setInterval(30000);
......@@ -60,10 +51,16 @@ BluetoothLinkProvider::BluetoothLinkProvider()
void BluetoothLinkProvider::onStart()
{
if (!mBluetoothServer) {
QBluetoothLocalDevice localDevice;
if (!localDevice.isValid()) {
qCWarning(KDECONNECT_CORE) << "No local bluetooth adapter found";
return;
}
mBluetoothServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
mBluetoothServer->setSecurityFlags(QBluetooth::Encryption | QBluetooth::Secure);
connect(mBluetoothServer, SIGNAL(newConnection()), this, SLOT(serverNewConnection()));
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
connectToPairedDevices();
#else
......@@ -72,8 +69,6 @@ void BluetoothLinkProvider::onStart()
connectTimer->start();
mKdeconnectService = mBluetoothServer->listen(mServiceUuid, "KDE Connect");
onNetworkChange(QNetworkSession::Connected);
}
void BluetoothLinkProvider::onStop()
......@@ -86,14 +81,15 @@ void BluetoothLinkProvider::onStop()
mKdeconnectService.unregisterService();
mBluetoothServer->close();
mBluetoothServer->deleteLater();
}
//I'm in a new network, let's be polite and introduce myself
void BluetoothLinkProvider::onNetworkChange(QNetworkSession::State state)
void BluetoothLinkProvider::onNetworkChange()
{
Q_UNUSED(state);
}
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
QList<QBluetoothAddress> BluetoothLinkProvider::getPairedDevices() {
QDBusConnection bus = QDBusConnection::systemBus();
QDBusInterface manager_iface("org.bluez", "/","org.bluez.Manager", bus);
......@@ -142,13 +138,14 @@ void BluetoothLinkProvider::connectToPairedDevices() {
socket->connectToService(pairedDevice, mServiceUuid);
}
}
#endif
void BluetoothLinkProvider::connectError()
{
QBluetoothSocket* socket = qobject_cast<QBluetoothSocket*>(sender());
if (!socket) return;
qCWarning(KDECONNECT_CORE) << "connectError: Couldn't connect to socket:" << socket->errorString();
qCWarning(KDECONNECT_CORE) << "Couldn't connect to socket:" << socket->errorString();
disconnect(socket, SIGNAL(connected()), this, SLOT(clientConnected()));
disconnect(socket, SIGNAL(readyRead()), this, SLOT(serverDataReceived()));
......@@ -177,7 +174,7 @@ void BluetoothLinkProvider::serviceDiscoveryFinished()
{
QList<QBluetoothServiceInfo> services = mServiceDiscoveryAgent->discoveredServices();
foreach (QBluetoothServiceInfo info, services) {
Q_FOREACH (QBluetoothServiceInfo info, services) {
if (mSockets.contains(info.device().address())) {
continue;
}
......@@ -189,10 +186,10 @@ void BluetoothLinkProvider::serviceDiscoveryFinished()
socket->connectToService(info);
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/serviceDiscoveryFinished: Connecting to " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Connecting to" << info.device().address();
if (socket->error() != QBluetoothSocket::NoSocketError) {
qCWarning(KDECONNECT_CORE) << "BluetoothLinkProvider/serviceDiscoveryFinished: Socket connection error: " << socket->errorString();
qCWarning(KDECONNECT_CORE) << "Socket connection error:" << socket->errorString();
}
}
}
......@@ -203,10 +200,10 @@ void BluetoothLinkProvider::clientConnected()
QBluetoothSocket* socket = qobject_cast<QBluetoothSocket*>(sender());
if (!socket) return;
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/clientConnected: Connected to " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Connected to" << socket->peerAddress();
if (mSockets.contains(socket->peerAddress())) {
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/clientConnected: Duplicate connection to " << socket->peerAddress().toString();
qCWarning(KDECONNECT_CORE()) << "Duplicate connection to" << socket->peerAddress();
socket->close();
socket->deleteLater();
return;
......@@ -237,14 +234,14 @@ void BluetoothLinkProvider::clientIdentityReceived()
bool success = NetworkPackage::unserialize(identityArray, &receivedPackage);
if (!success || receivedPackage.type() != PACKAGE_TYPE_IDENTITY) {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider/clientIdentityReceived: Not an identification package (wuh?)";
qCWarning(KDECONNECT_CORE) << "Not an identity package";
mSockets.remove(socket->peerAddress());
socket->close();
socket->deleteLater();
return;
}
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/clientIdentityReceived: Received identity package from " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Received identity package from" << socket->peerAddress();
disconnect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(connectError()));
......@@ -280,10 +277,10 @@ void BluetoothLinkProvider::serverNewConnection()
{
QBluetoothSocket* socket = mBluetoothServer->nextPendingConnection();
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/serverNewConnection:" << "Received connection from " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Received connection from" << socket->peerAddress();
if (mSockets.contains(socket->peerAddress())) {
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/serverNewConnection: Duplicate connection from " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Duplicate connection from" << socket->peerAddress();
socket->close();
socket->deleteLater();
return;
......@@ -297,7 +294,7 @@ void BluetoothLinkProvider::serverNewConnection()
NetworkPackage::createIdentityPackage(&np2);
socket->write(np2.serialize());
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/serverNewConnection: Sent identity package to " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Sent identity package to" << socket->peerAddress();
mSockets.insert(socket->peerAddress(), socket);
}
......@@ -320,14 +317,14 @@ void BluetoothLinkProvider::serverDataReceived()
bool success = NetworkPackage::unserialize(identityArray, &receivedPackage);
if (!success || receivedPackage.type() != PACKAGE_TYPE_IDENTITY) {
qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider/serverDataReceived: Not an identity package.";
qCWarning(KDECONNECT_CORE) << "Not an identity package.";
mSockets.remove(socket->peerAddress());
socket->close();
socket->deleteLater();
return;
}
qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/serverDataReceived: Received identity package from " << socket->peerAddress().toString();
qCDebug(KDECONNECT_CORE()) << "Received identity package from" << socket->peerAddress();
const QString& deviceId = receivedPackage.get<QString>("deviceId");
BluetoothDeviceLink* deviceLink = new BluetoothDeviceLink(deviceId, this, socket);
......@@ -342,7 +339,6 @@ void BluetoothLinkProvider::serverDataReceived()
void BluetoothLinkProvider::deviceLinkDestroyed(QObject* destroyedDeviceLink)
{
//kDebug(debugArea()) << "deviceLinkDestroyed";
const QString id = destroyedDeviceLink->property("deviceId").toString();
qCDebug(KDECONNECT_CORE()) << "Device disconnected:" << id;
QMap< QString, DeviceLink* >::iterator oldLinkIterator = mLinks.find(id);
......
/**
* Copyright 2015 Saikrishna Arcot <saiarcot895@gmail.com>
* Copyright 2016 Saikrishna Arcot <saiarcot895@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -22,6 +22,7 @@
#define BLUETOOTHLINKPROVIDER_H
#include <QObject>
#include <QPointer>
#include <QTimer>
#include <QtBluetooth/QBluetoothAddress>
#include <QtBluetooth/QBluetoothLocalDevice>
......@@ -35,28 +36,31 @@
class BluetoothDeviceLink;
class BluetoothLinkProvider
class KDECONNECTCORE_EXPORT BluetoothLinkProvider
: public LinkProvider
{
Q_OBJECT
public:
BluetoothLinkProvider();
~BluetoothLinkProvider();
virtual ~BluetoothLinkProvider();
QString name() override { return "BluetoothLinkProvider"; }
int priority() override { return PRIORITY_MEDIUM; }
QString name() { return "BluetoothLinkProvider"; }
int priority() { return PRIORITY_MEDIUM; }
public Q_SLOTS:
virtual void onNetworkChange(QNetworkSession::State state);
virtual void onStart();
virtual void onStop();
virtual void onNetworkChange() override;
virtual void onStart() override;
virtual void onStop() override;
void connectError();
void serviceDiscoveryFinished();
private Q_SLOTS:
void deviceLinkDestroyed(QObject* destroyedDeviceLink);
void socketDisconnected();
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
void connectToPairedDevices();
#endif
void serverNewConnection();
void serverDataReceived();
void clientConnected();
......@@ -66,9 +70,8 @@ private:
void addLink(BluetoothDeviceLink* deviceLink, const QString& deviceId);
QList<QBluetoothAddress> getPairedDevices();
QBluetoothLocalDevice mDevice;
QBluetoothUuid mServiceUuid;
QBluetoothServer* mBluetoothServer;
QPointer<QBluetoothServer> mBluetoothServer;
QBluetoothServiceInfo mKdeconnectService;
QBluetoothServiceDiscoveryAgent* mServiceDiscoveryAgent;
QTimer* connectTimer;
......
/**
* Copyright 2015 Vineet Garg <grg.vineet@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <KLocalizedString>
#include "core_debug.h"
#include "daemon.h"
#include "kdeconnectconfig.h"
#include "bluetoothpairinghandler.h"
#include "networkpackagetypes.h"
BluetoothPairingHandler::BluetoothPairingHandler(DeviceLink* deviceLink)
: PairingHandler(deviceLink)
, m_status(NotPaired)
{
m_pairingTimeout.setSingleShot(true);
m_pairingTimeout.setInterval(30 * 1000); //30 seconds of timeout
connect(&m_pairingTimeout, &QTimer::timeout, this, &BluetoothPairingHandler::pairingTimeout);
}
void BluetoothPairingHandler::packageReceived(const NetworkPackage& np)
{
qCDebug(KDECONNECT_CORE) << "Pairing package received!" << np.serialize();
m_pairingTimeout.stop();
bool wantsPair = np.get<bool>("pair");
if (wantsPair) {
if (isPairRequested()) { //We started pairing
qCDebug(KDECONNECT_CORE) << "Pair answer";
setInternalPairStatus(Paired);
} else {
qCDebug(KDECONNECT_CORE) << "Pair request";
if (isPaired()) { //I'm already paired, but they think I'm not
acceptPairing();
return;
}
Daemon::instance()->askPairingConfirmation(this);
setInternalPairStatus(RequestedByPeer);
}
} else { //wantsPair == false
qCDebug(KDECONNECT_CORE) << "Unpair request";
setInternalPairStatus(NotPaired);
if (isPairRequested()) {
Q_EMIT pairingError(i18n("Canceled by other peer"));
}
}
}
bool BluetoothPairingHandler::requestPairing()
{
switch (m_status) {
case Paired:
Q_EMIT pairingError(i18n("%1: Already paired", deviceLink()->name()));
return false;
case Requested:
Q_EMIT pairingError(i18n("%1: Pairing already requested for this device", deviceLink()->name()));
return false;
case RequestedByPeer:
qCDebug(KDECONNECT_CORE) << deviceLink()->name() << " : Pairing already started by the other end, accepting their request.";
acceptPairing();
return false;
case NotPaired:
;
}
NetworkPackage np(PACKAGE_TYPE_PAIR);
np.set("pair", true);
bool success;
success = deviceLink()->sendPackage(np);
if (success) {