From 54ef8862ebaea1c1c76f71e3ddbe4a87a73bcc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80lex=20Fiestas?= Date: Wed, 24 May 2017 23:28:49 +0200 Subject: [PATCH] (Bluetooth) Remove compatibility with Qt < 5.4.0 --- .../bluetooth/bluetoothlinkprovider.cpp | 60 +------------------ .../bluetooth/bluetoothlinkprovider.h | 4 +- 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/core/backends/bluetooth/bluetoothlinkprovider.cpp b/core/backends/bluetooth/bluetoothlinkprovider.cpp index fca2032de..6a8855f6d 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.cpp +++ b/core/backends/bluetooth/bluetoothlinkprovider.cpp @@ -39,14 +39,11 @@ BluetoothLinkProvider::BluetoothLinkProvider() connectTimer = new QTimer(this); connectTimer->setInterval(30000); connectTimer->setSingleShot(false); -#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) - connect(connectTimer, SIGNAL(timeout()), this, SLOT(connectToPairedDevices())); -#else + mServiceDiscoveryAgent = new QBluetoothServiceDiscoveryAgent(this); mServiceDiscoveryAgent->setUuidFilter(mServiceUuid); connect(mServiceDiscoveryAgent, SIGNAL(finished()), this, SLOT(serviceDiscoveryFinished())); connect(connectTimer, SIGNAL(timeout()), mServiceDiscoveryAgent, SLOT(start())); -#endif } void BluetoothLinkProvider::onStart() @@ -61,11 +58,7 @@ void BluetoothLinkProvider::onStart() mBluetoothServer->setSecurityFlags(QBluetooth::Encryption | QBluetooth::Secure); connect(mBluetoothServer, SIGNAL(newConnection()), this, SLOT(serverNewConnection())); -#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) - connectToPairedDevices(); -#else mServiceDiscoveryAgent->start(); -#endif connectTimer->start(); mKdeconnectService = mBluetoothServer->listen(mServiceUuid, "KDE Connect"); @@ -89,57 +82,6 @@ void BluetoothLinkProvider::onNetworkChange() { } -#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0) -QList BluetoothLinkProvider::getPairedDevices() { - QDBusConnection bus = QDBusConnection::systemBus(); - QDBusInterface manager_iface("org.bluez", "/","org.bluez.Manager", bus); - - QDBusReply devices = manager_iface.call("DefaultAdapter"); - - if (!devices.isValid()) { - qCWarning(KDECONNECT_CORE) << "Couldn't get default adapter:" << devices.error(); - return QList(); - } - - QDBusObjectPath defaultAdapter = devices.value(); - QString defaultAdapterPath = defaultAdapter.path(); - - QDBusInterface devices_iface("org.bluez", defaultAdapterPath, "org.bluez.Adapter", bus); - QDBusMessage pairedDevices = devices_iface.call("ListDevices"); - - QDBusArgument pairedDevicesArg = pairedDevices.arguments().at(0).value(); - pairedDevicesArg.beginArray(); - QList pairedDevicesList; - - while (!pairedDevicesArg.atEnd()) { - QVariant variant = pairedDevicesArg.asVariant(); - QDBusObjectPath pairedDevice = qvariant_cast(variant); - QString pairedDevicePath = pairedDevice.path(); - QString pairedDeviceMac = pairedDevicePath.split(QChar('/')).last().remove("dev_").replace("_", ":"); - pairedDevicesList.append(QBluetoothAddress(pairedDeviceMac)); - } - - return pairedDevicesList; -} - -void BluetoothLinkProvider::connectToPairedDevices() { - QList pairedDevices = getPairedDevices(); - for (int i = 0; i < pairedDevices.size(); i++) { - QBluetoothAddress pairedDevice = pairedDevices.at(i); - - if (mSockets.contains(pairedDevice)) { - continue; - } - - QBluetoothSocket* socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this); - connect(socket, SIGNAL(connected()), this, SLOT(clientConnected())); - connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(connectError())); - qCDebug(KDECONNECT_CORE()) << "BluetoothLinkProvider/onStart: Connecting to " << pairedDevice.toString(); - socket->connectToService(pairedDevice, mServiceUuid); - } -} -#endif - void BluetoothLinkProvider::connectError() { QBluetoothSocket* socket = qobject_cast(sender()); diff --git a/core/backends/bluetooth/bluetoothlinkprovider.h b/core/backends/bluetooth/bluetoothlinkprovider.h index bced59172..ccdc6a35a 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.h +++ b/core/backends/bluetooth/bluetoothlinkprovider.h @@ -58,9 +58,7 @@ public Q_SLOTS: 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();