Make optional bluetooth and MDNS build against KF6 too

This commit is contained in:
Alexander Lohnau 2023-07-21 21:12:18 +02:00
parent e00ffbb4f6
commit a3fc5eaf9f
3 changed files with 34 additions and 7 deletions

View file

@ -74,7 +74,7 @@ endif()
if (BLUETOOTH_ENABLED) if (BLUETOOTH_ENABLED)
target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_BLUETOOTH) target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_BLUETOOTH)
target_link_libraries(kdeconnectcore PRIVATE Qt5::Bluetooth) target_link_libraries(kdeconnectcore PRIVATE Qt${QT_MAJOR_VERSION}::Bluetooth)
endif() endif()
if (LOOPBACK_ENABLED) if (LOOPBACK_ENABLED)
@ -83,7 +83,7 @@ endif()
if (MDNS_ENABLED) if (MDNS_ENABLED)
target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_MDNS) target_compile_definitions(kdeconnectcore PRIVATE -DKDECONNECT_MDNS)
target_link_libraries(kdeconnectcore PRIVATE KF5::DNSSD) target_link_libraries(kdeconnectcore PRIVATE KF${QT_MAJOR_VERSION}::DNSSD)
endif() endif()
set_target_properties(kdeconnectcore PROPERTIES set_target_properties(kdeconnectcore PROPERTIES

View file

@ -38,7 +38,7 @@ void BluetoothLinkProvider::onStart()
} }
mBluetoothServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); mBluetoothServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this);
mBluetoothServer->setSecurityFlags(QBluetooth::Encryption | QBluetooth::Secure); mBluetoothServer->setSecurityFlags(QBluetooth::Security::Encryption | QBluetooth::Security::Secure);
connect(mBluetoothServer, SIGNAL(newConnection()), this, SLOT(serverNewConnection())); connect(mBluetoothServer, SIGNAL(newConnection()), this, SLOT(serverNewConnection()));
mServiceDiscoveryAgent->start(); mServiceDiscoveryAgent->start();
@ -111,7 +111,7 @@ void BluetoothLinkProvider::serviceDiscovered(const QBluetoothServiceInfo &old_i
qCDebug(KDECONNECT_CORE()) << "Connecting to" << info.device().address(); qCDebug(KDECONNECT_CORE()) << "Connecting to" << info.device().address();
if (socket->error() != QBluetoothSocket::NoSocketError) { if (socket->error() != QBluetoothSocket::SocketError::NoSocketError) {
qCWarning(KDECONNECT_CORE) << "Socket connection error:" << socket->errorString(); qCWarning(KDECONNECT_CORE) << "Socket connection error:" << socket->errorString();
} }
} }

View file

@ -125,10 +125,16 @@ bool ConnectionMultiplexer::tryParseMessage()
*/ */
char message_type = header[0]; char message_type = header[0];
uint16_t message_length = qFromBigEndian<uint16_t>(&header.data()[1]); uint16_t message_length = qFromBigEndian<uint16_t>(&header.data()[1]);
#if QT_VERSION_MAJOR == 5
quint128 message_uuid_raw; quint128 message_uuid_raw;
for (int i = 0; i < 16; ++i) for (int i = 0; i < 16; ++i) {
message_uuid_raw.data[i] = header[3 + i]; message_uuid_raw.data[i] = header[3 + i];
}
QBluetoothUuid message_uuid = QBluetoothUuid(message_uuid_raw); QBluetoothUuid message_uuid = QBluetoothUuid(message_uuid_raw);
#else
const QByteArray uuisByteArray = header.sliced(3, 16); // Faster than mid, see https://doc.qt.io/qt-6/qbytearray.html#mid
QBluetoothUuid message_uuid = QBluetoothUuid::fromBytes(uuisByteArray.constData());
#endif
// Check if we have the full message including its data // Check if we have the full message including its data
QByteArray data = mSocket->read(message_length); QByteArray data = mSocket->read(message_length);
@ -229,8 +235,13 @@ QBluetoothUuid ConnectionMultiplexer::newChannel()
message[0] = MESSAGE_OPEN_CHANNEL; message[0] = MESSAGE_OPEN_CHANNEL;
qToBigEndian<uint16_t>(0, &message.data()[1]); qToBigEndian<uint16_t>(0, &message.data()[1]);
quint128 new_id_raw = new_id.toUInt128(); #if QT_VERSION_MAJOR == 5
message.append((const char *)new_id_raw.data, 16); quint128 id_raw = new_id.toUInt128();
message.append((const char *)id_raw.data, 16);
#else
const auto channelBytes = new_id.toByteArray();
message.append(channelBytes.constData(), 16);
#endif
to_write_bytes.append(message); to_write_bytes.append(message);
// Add the channel ourselves // Add the channel ourselves
@ -337,8 +348,13 @@ void ConnectionMultiplexer::channelCanRead(QBluetoothUuid channelId)
QByteArray message(3, (char)0); QByteArray message(3, (char)0);
message[0] = MESSAGE_READ; message[0] = MESSAGE_READ;
qToBigEndian<uint16_t>(2, &message.data()[1]); qToBigEndian<uint16_t>(2, &message.data()[1]);
#if QT_VERSION_MAJOR == 5
quint128 id_raw = channelId.toUInt128(); quint128 id_raw = channelId.toUInt128();
message.append((const char *)id_raw.data, 16); message.append((const char *)id_raw.data, 16);
#else
const auto channelBytes = channelId.toByteArray();
message.append(channelBytes.constData(), 16);
#endif
message.append(2, 0); message.append(2, 0);
qToBigEndian<int16_t>(read_amount, &message.data()[19]); qToBigEndian<int16_t>(read_amount, &message.data()[19]);
to_write_bytes.append(message); to_write_bytes.append(message);
@ -367,8 +383,14 @@ void ConnectionMultiplexer::channelCanWrite(QBluetoothUuid channelId)
message[0] = MESSAGE_WRITE; message[0] = MESSAGE_WRITE;
qToBigEndian<uint16_t>(amount, &message.data()[1]); qToBigEndian<uint16_t>(amount, &message.data()[1]);
#if QT_VERSION_MAJOR == 5
quint128 id_raw = channelId.toUInt128(); quint128 id_raw = channelId.toUInt128();
message.append((const char *)id_raw.data, 16); message.append((const char *)id_raw.data, 16);
#else
const auto channelBytes = channelId.toByteArray();
message.append(channelBytes.constData(), 16);
#endif
message.append(data); message.append(data);
to_write_bytes.append(message); to_write_bytes.append(message);
// Try to send it immediately // Try to send it immediately
@ -405,8 +427,13 @@ void ConnectionMultiplexer::closeChannel(QBluetoothUuid channelId)
message[0] = MESSAGE_CLOSE_CHANNEL; message[0] = MESSAGE_CLOSE_CHANNEL;
qToBigEndian<uint16_t>(0, &message.data()[1]); qToBigEndian<uint16_t>(0, &message.data()[1]);
#if QT_VERSION_MAJOR == 5
quint128 id_raw = channelId.toUInt128(); quint128 id_raw = channelId.toUInt128();
message.append((const char *)id_raw.data, 16); message.append((const char *)id_raw.data, 16);
#else
const auto channelBytes = channelId.toByteArray();
message.append(channelBytes.constData(), 16);
#endif
to_write_bytes.append(message); to_write_bytes.append(message);
// Try to send it immediately // Try to send it immediately
bytesWritten(); bytesWritten();