Make optional bluetooth and MDNS build against KF6 too
This commit is contained in:
parent
e00ffbb4f6
commit
a3fc5eaf9f
3 changed files with 34 additions and 7 deletions
|
@ -74,7 +74,7 @@ endif()
|
|||
|
||||
if (BLUETOOTH_ENABLED)
|
||||
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()
|
||||
|
||||
if (LOOPBACK_ENABLED)
|
||||
|
@ -83,7 +83,7 @@ endif()
|
|||
|
||||
if (MDNS_ENABLED)
|
||||
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()
|
||||
|
||||
set_target_properties(kdeconnectcore PROPERTIES
|
||||
|
|
|
@ -38,7 +38,7 @@ void BluetoothLinkProvider::onStart()
|
|||
}
|
||||
|
||||
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()));
|
||||
|
||||
mServiceDiscoveryAgent->start();
|
||||
|
@ -111,7 +111,7 @@ void BluetoothLinkProvider::serviceDiscovered(const QBluetoothServiceInfo &old_i
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,10 +125,16 @@ bool ConnectionMultiplexer::tryParseMessage()
|
|||
*/
|
||||
char message_type = header[0];
|
||||
uint16_t message_length = qFromBigEndian<uint16_t>(&header.data()[1]);
|
||||
#if QT_VERSION_MAJOR == 5
|
||||
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];
|
||||
}
|
||||
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
|
||||
QByteArray data = mSocket->read(message_length);
|
||||
|
@ -229,8 +235,13 @@ QBluetoothUuid ConnectionMultiplexer::newChannel()
|
|||
message[0] = MESSAGE_OPEN_CHANNEL;
|
||||
qToBigEndian<uint16_t>(0, &message.data()[1]);
|
||||
|
||||
quint128 new_id_raw = new_id.toUInt128();
|
||||
message.append((const char *)new_id_raw.data, 16);
|
||||
#if QT_VERSION_MAJOR == 5
|
||||
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);
|
||||
|
||||
// Add the channel ourselves
|
||||
|
@ -337,8 +348,13 @@ void ConnectionMultiplexer::channelCanRead(QBluetoothUuid channelId)
|
|||
QByteArray message(3, (char)0);
|
||||
message[0] = MESSAGE_READ;
|
||||
qToBigEndian<uint16_t>(2, &message.data()[1]);
|
||||
#if QT_VERSION_MAJOR == 5
|
||||
quint128 id_raw = channelId.toUInt128();
|
||||
message.append((const char *)id_raw.data, 16);
|
||||
#else
|
||||
const auto channelBytes = channelId.toByteArray();
|
||||
message.append(channelBytes.constData(), 16);
|
||||
#endif
|
||||
message.append(2, 0);
|
||||
qToBigEndian<int16_t>(read_amount, &message.data()[19]);
|
||||
to_write_bytes.append(message);
|
||||
|
@ -367,8 +383,14 @@ void ConnectionMultiplexer::channelCanWrite(QBluetoothUuid channelId)
|
|||
message[0] = MESSAGE_WRITE;
|
||||
qToBigEndian<uint16_t>(amount, &message.data()[1]);
|
||||
|
||||
#if QT_VERSION_MAJOR == 5
|
||||
quint128 id_raw = channelId.toUInt128();
|
||||
message.append((const char *)id_raw.data, 16);
|
||||
#else
|
||||
const auto channelBytes = channelId.toByteArray();
|
||||
message.append(channelBytes.constData(), 16);
|
||||
#endif
|
||||
|
||||
message.append(data);
|
||||
to_write_bytes.append(message);
|
||||
// Try to send it immediately
|
||||
|
@ -405,8 +427,13 @@ void ConnectionMultiplexer::closeChannel(QBluetoothUuid channelId)
|
|||
message[0] = MESSAGE_CLOSE_CHANNEL;
|
||||
qToBigEndian<uint16_t>(0, &message.data()[1]);
|
||||
|
||||
#if QT_VERSION_MAJOR == 5
|
||||
quint128 id_raw = channelId.toUInt128();
|
||||
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);
|
||||
// Try to send it immediately
|
||||
bytesWritten();
|
||||
|
|
Loading…
Reference in a new issue